import '@tarojs/async-await'
import { connect, Provider } from '@tarojs/redux'
import Taro, { Component } from '@tarojs/taro'
import Index from './pages/index'
import dva from './utils/dva'
import models from './models'
import './app.less'

// 如果需要在 h5 环境中开启 React Devtools
// 取消以下注释：
// if (process.env.NODE_ENV !== 'production' && process.env.TARO_ENV === 'h5')  {
//   require('nerv-devtools')
// }
const dvaApp = dva.createApp({
  initialState: {},
  models: models,
});

const store = dvaApp.getStore();

@connect(({ common }) => ({ common }))
class App extends Component {

  config = {
    pages: [
      'pages/authorize/index',
      'pages/home/index',
      'pages/order/index',
      'pages/mine/index',
      'pages/listDetails/index',
      'pages/feedback/index',
      'pages/members/index',
      'pages/balance/index',
      'pages/collection/index',
      'pages/share/index',
      'pages/template/index',
      'pages/goodsDetails/index',
      'pages/confirmOrder/index',
      'pages/successOrder/index',
      'pages/coupons/index',
      'pages/orderInformation/index',
      'pages/businessLicense/index',
      'pages/about/index',
    ],
    window: {
      backgroundTextStyle: 'light',
      navigationBarBackgroundColor: '#fff',
      navigationBarTitleText: 'WeChat',
      navigationBarTextStyle: 'black'
    },
    tabBar: {
      color: '#000000',
      selectedColor: '#2196f3',
      backgroundColor: '#fff',
      borderStyle: 'white',
      list: [{
        text:'首页',
        pagePath: 'pages/home/index',
        iconPath: './img/home.png',
        selectedIconPath: './img/home1.png'
      },{
        text:'订单',
        pagePath: 'pages/order/index',
        iconPath: './img/order.png',
        selectedIconPath: './img/order1.png'
      },{
        text:'我的',
        pagePath: 'pages/mine/index',
        iconPath: './img/mine.png',
        selectedIconPath: './img/mine1.png'
      }]
    }
  }
  //
  // componentDidMount() {
  //   Taro.checkSession({
  //     success () {
  //       //session_key 未过期，并且在本生命周期一直有效
  //       Taro.switchTab({ url: './pages/home/index' });
  //     },
  //     fail () {
  //       // session_key 已经失效，需要重新执行登录流程
  //       Taro.login() //重新登录
  //     }
  //   })
  // }
  componentDidMount () {
  console.log('App componentDidMount');
  const { dispatch } = this.props;
  dispatch({ type: 'common/init' });
  }

  // 在 App 类中的 render() 函数没有实际作用
  // 请勿修改此函数
  render () {
      return <Provider store={store}><Index /></Provider>
  }
}

Taro.render(<App />, document.getElementById('app'))
